#include "MSentenceManage.h"

using namespace ns_yht;

MSentenceManage::MSentenceManage()
{
}

MSentenceManage::~MSentenceManage()
{
}

// void MSentenceManage::reset(int id)
// {
//     sentenceBuffer[id].totalNumber = 0;
//     sentenceBuffer[id].nCount = 0;
// }

bool MSentenceManage::isReady(int id)
{
    // qInfo() << "MSentenceManage::isReady(int id) ============" <<id<< (sentenceBuffer[id].totalNumber > 0 && sentenceBuffer[id].totalNumber == sentenceBuffer[id].nCount);
    // dbg("MSentenceManage::isReady(int id) ============" , id , (sentenceBuffer[id].totalNumber > 0 && sentenceBuffer[id].totalNumber == sentenceBuffer[id].nCount));
    return (sentenceBuffer[id].totalNumber > 0 && sentenceBuffer[id].totalNumber == sentenceBuffer[id].nCount);
}

void MSentenceManage::insert(int id, int totalNumber, int index, const QByteArray &part)
{
    // qInfo() << "MSentenceManage::insert=============================" << id << totalNumber << index << part;
    // dbg("MSentenceManage::insert=============================" , id , totalNumber , index , part);
    if (index == 1)
    {
        sentenceBuffer[id].totalNumber = totalNumber;
        // sentenceBuffer[id].nCount = 0;
    }
    sentenceBuffer[id].parts[index - 1] = part;
    sentenceBuffer[id].nCount++;
}

QByteArray MSentenceManage::getSentence(int id)
{
    QByteArray sentence;
    for (int i = 0; i < sentenceBuffer[id].totalNumber; i++)
    {
        sentence += sentenceBuffer[id].parts[i];
    }
    // sentenceBuffer[id].totalNumber = totalNumber;
    sentenceBuffer[id].nCount = 0;
    // qInfo() << "MSentenceManage::getSentence==================================" << id << sentence;
    // dbg("MSentenceManage::getSentence==================================", id, sentence);
    return sentence;
}
